﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameControl;
public class CollectableItem : CombinableItem
{
    public CollectableItemField NewSetting = new CollectableItemField();
    public override ItemField ItemFieldSetting { get => NewSetting; set => NewSetting = value as CollectableItemField; }
    public override void DownloadInstanceField(object args)
    {
        base.DownloadInstanceField(args);
        (ItemFieldSetting as CollectableItemField).CanCollectItemName = (args as CollectableItemField).CanCollectItemName;
        try
        {
            this.sprite.GetComponent<SpriteRenderer>().sprite = GameManager.Get<IItemInstantiateManager>().GetItemSettingByName((GetComponent<CollectableItem>().ItemFieldSetting as CollectableItemField).CanCollectItemName).transform.Find("Sprite").GetComponent<SpriteRenderer>().sprite;

        }
        catch(KeyNotFoundException e)
        {
            Debug.LogError($"{this}:未找到该物品{GetField<CollectableItemField>().CanCollectItemName}");
            QxFramework.Core.MessageManager.Instance.Get<GameMap.ItemMapEvent>().DispatchMessage(GameMap.ItemMapEvent.DeleteInMap,this,
                new GameMap.ItemMapArgs { ItemName = ItemFieldSetting.ItemName },null,false);
        }
    }
    public override ItemField UploadInstanceField()
    {
        var tp = base.UploadInstanceField() as CollectableItemField;
        tp.CanCollectItemName = (ItemFieldSetting as CollectableItemField).CanCollectItemName;
        return tp;
    }
    public override void OnPreferenceDestory()
    {
        base.OnPreferenceDestory();
    }
    public override void OnRealDestory()
    {
    //    base.OnRealDestory();
    }
}
[System.Serializable]
public class CollectableItemField : CombinableItemField
{
    public string CanCollectItemName;
}